//
//  TaskCell.m
//  Zhiche-Carriage
//
//  Created by 王亚陆 on 16/7/7.
//  Copyright © 2016年 LeeBruce. All rights reserved.
//

#import "TaskCell.h"
#import <Masonry.h>
@implementation TaskCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        
        self.view = [[UIView alloc]initWithFrame:CGRectMake(0, 13, screenWidth, 227*kHeight)];
        self.contentView.backgroundColor = GrayColor;
        self.view.backgroundColor = WhiteColor;
        [self.contentView addSubview:self.view];
        
        self.number = [self createUIlabel:@"运单号:" andFont:FontOfSize12 andColor:littleBlackColor];
        self.orderNumber = [self createUIlabel:@"" andFont:FontOfSize12 andColor:littleBlackColor];
        
        self.time = [self createUIlabel:@"" andFont:FontOfSize14 andColor:BlackColor];
        self.time.textColor = RGBACOLOR(254, 110, 19, 1);
        [self.view addSubview:self.number];
        [self.view addSubview:self.orderNumber];
        [self.view addSubview:self.time];
        [self.number mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.view.mas_left).with.offset(18*kWidth);
            make.top.mas_equalTo(self.view.mas_top).with.offset(15*kHeight);
        }];
        [self.orderNumber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.number.mas_right).with.offset(10*kWidth);
            make.top.mas_equalTo(self.view.mas_top).with.offset(15*kHeight);
        }];
        [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.view.mas_right).with.offset(-14*kWidth);
            make.top.mas_equalTo(self.view.mas_top).with.offset(15*kHeight);
        }];
        
        self.scrollView = [[UIScrollView alloc]init];
        self.scrollView.contentSize = CGSizeMake(screenWidth + 150*2*kWidth, 20*kHeight);
        self.scrollView.alwaysBounceHorizontal = YES;
        self.scrollView.showsHorizontalScrollIndicator = NO;
        [self.view addSubview:self.scrollView];
        
        self.carStyle = [self createUIlabel:@"" andFont:FontOfSize12 andColor:carScrollColor];
        [self.scrollView addSubview:self.carStyle];
        //省市县
        self.startAddress = [self createUIlabel:@"" andFont:FontOfSize14 andColor:littleBlackColor];
        //发车单位 收车单位  长沙芒果库
        self.startDetailAddress = [self createUIlabel:@"" andFont:FontOfSize10 andColor:littleBlackColor];
        self.startDetailAddress.numberOfLines = 2;
        self.startTimeL = [self createUIlabel:@"" andFont:FontOfSize10 andColor:littleBlackColor];
        self.endAddress = [self createUIlabel:@"" andFont:FontOfSize14 andColor:littleBlackColor];
        //湖南益阳宝马4S店
        self.endDetailAddress = [self createUIlabel:@"" andFont:FontOfSize10 andColor:littleBlackColor];
        self.endDetailAddress.numberOfLines = 2;
        self.endTimeL = [self createUIlabel:@"" andFont:FontOfSize10 andColor:littleBlackColor];
        [self.view addSubview:self.startAddress];
        [self.view addSubview:self.startDetailAddress];
        [self.view addSubview:self.startTimeL];
        [self.view addSubview:self.endAddress];
        [self.view addSubview:self.endDetailAddress];
        [self.view addSubview:self.endTimeL];
        
        UIImageView * imageLogo = [[UIImageView alloc]init];
        imageLogo.image = [UIImage imageNamed:@"Quote_Cell_logo"];
        [self.view addSubview:imageLogo];
        [imageLogo mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.view.mas_centerX);
            make.centerY.mas_equalTo(self.view.mas_top).with.offset(90*kHeight);
        }];
        
        
        [self.startTimeL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.view.mas_left).with.offset(53*kHeight);
            make.top.mas_equalTo(self.view.mas_top).with.offset(59*kHeight);
        }];
        [self.endTimeL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.view.mas_right).with.offset(-56*kHeight);
            make.top.mas_equalTo(self.view.mas_top).with.offset(59*kHeight);
        }];
        
        [self.startAddress mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.startTimeL.mas_centerX);
            make.top.mas_equalTo(self.startTimeL.mas_bottom).with.offset(9*kHeight);
        }];
        
        [self.startDetailAddress mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.startAddress.mas_centerX);
            make.top.mas_equalTo(self.startAddress.mas_bottom).with.offset(9*kHeight);
            make.width.mas_equalTo(90*kWidth);
            
        }];
        
        [self.endAddress mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.endTimeL.mas_centerX);
            make.top.mas_equalTo(self.endTimeL.mas_bottom).with.offset(9*kHeight);
        }];
        [self.endDetailAddress mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.endAddress.mas_centerX);
            make.top.mas_equalTo(self.endAddress.mas_bottom).with.offset(9*kHeight);
            make.width.mas_equalTo(90*kWidth);
            
        }];
        
        UIView * viewline = [[UIView alloc]init];
        viewline.backgroundColor = LineGrayColor;
        [self.view addSubview:viewline];
        [viewline mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.view.mas_top).with.offset(45*kHeight);
            make.left.mas_equalTo(self.view.mas_left);
            make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
        }];
        
        
        _Btn3 = [self createBtn:@"" andbackcolor:YellowColor andbordercolor:YellowColor andtitlecolor:WhiteColor];
        
        _line1=[[UIView alloc]init];
        _line1.backgroundColor = LineGrayColor;
        [self.view addSubview:_line1];
        _line2=[[UIView alloc]init];
        _line2.backgroundColor = LineGrayColor;
        [self.view addSubview:_line2];
        
    }
    return self;
}

-(void)showInfo:(NSDictionary *)dic_info{
//    {
//        arriveDate = "2016-06-29";
//        deliveryDate = "2016-06-29";
//        departCityName = "\U5317\U4eac\U5e02";
//        departUnit = fans;
//        id = 277;
//        orderCode = 748054519754625024;
//        receiptCityName = "\U5929\U6d25\U5e02";
//        receiptUnit = Shouchedanwei;
//        status = 45;
//        statusText = "\U5f85\U63d0\U8f66";
//        vehicles =     (
//                        {
//                            amount = 1;
//                            brand = "<null>";
//                            brandName = "\U5965\U8fea\U5965\U8feaQ2";
//                            id = 307;
//                            vehicleName = "\U5965\U8feaQ2";
//                        }
//                        );
//    }

    self.orderNumber.text = [NSString stringWithFormat:@"%@", dic_info[@"orderCode"]];
    self.time.text =[NSString stringWithFormat:@"%@",dic_info[@"statusText"]];
    NSString * startAddress = [NSString stringWithFormat:@"%@",dic_info[@"departCityName"]];
    self.startAddress.text = startAddress;//省市县
    self.startDetailAddress.text = [NSString stringWithFormat:@"%@",dic_info[@"departUnit"]];//发车单位
    self.startTimeL.text = [NSString stringWithFormat:@"%@", dic_info[@"deliveryDate"]];//发车时间
    NSString * endAddress = [NSString stringWithFormat:@"%@",dic_info[@"receiptCityName"]];
    self.endAddress.text = endAddress;//省市县
    self.endDetailAddress.text =  [NSString stringWithFormat:@"%@",dic_info[@"receiptUnit"]];//收车单位
    self.endTimeL.text = [NSString stringWithFormat:@"%@",dic_info[@"arriveDate"]];//到达时间
    

    int statu =[dic_info[@"status"] intValue];
    if (statu ==40||statu==45||statu==50) {
        switch (statu) {
            case 40:
                [self.Btn3 setTitle:@"前往提车" forState:UIControlStateNormal];
                break;
            case 45:
                [self.Btn3 setTitle:@"现场提车" forState:UIControlStateNormal];
                break;
            case 50:
                [self.Btn3 setTitle:@"送达交车" forState:UIControlStateNormal];
                break;
            default:
                break;
        }
    }else{
        self.Btn3.hidden = YES;
    }
    
    [_line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
        make.top.mas_equalTo(self.view.mas_top).with.offset(135*kHeight);
    }];
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_line1.mas_bottom).offset(0*kHeight);
        make.left.mas_equalTo(self.view.mas_left).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(screenWidth, 43*kHeight));
    }];
    [_line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
        make.top.mas_equalTo(self.scrollView.mas_bottom).with.offset(0*kHeight);
    }];
    
    
    NSMutableArray * carstyle = dic_info[@"vehicles"];
    NSString * carName = [[NSString alloc]init];
    for (int i=0; i<carstyle.count; i++) {
        carName = [carName stringByAppendingString:[NSString stringWithFormat:@"%@-%@辆   ",carstyle[i][@"vehicleName"],carstyle[i][@"amount"]]];
    }
    self.carStyle.text = carName;
    self.carStyle.textAlignment = NSTextAlignmentLeft;
    [self.carStyle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.scrollView.mas_left).with.offset(18*kWidth);
        make.centerY.mas_equalTo(self.scrollView.mas_centerY);
    }];
    NSLog(@"%f",self.carStyle.frame.size.width);
    self.scrollView.contentSize = CGSizeMake(self.carStyle.frame.size.width, 20*kHeight);
    [self.view addSubview:_Btn2];
    [self.view addSubview:_Btn3];
    
    [_Btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.view.mas_right).with.offset(-14*kWidth);
        make.size.mas_equalTo(CGSizeMake(70*kWidth, 30*kHeight));
        make.top.mas_equalTo(self.scrollView.mas_bottom).with.offset(8*kHeight);
    }];
    
    
}

-(NewBtn*)createBtn:(NSString*)title andbackcolor:(UIColor*)backcolor andbordercolor:(UIColor*)bordercolor andtitlecolor:(UIColor*)titlecolor {
    
    NewBtn * btn = [NewBtn buttonWithType:UIButtonTypeCustom];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:titlecolor forState:UIControlStateNormal];
    btn.titleLabel.font = Font(FontOfSize14);
    btn.backgroundColor = backcolor;
    
    btn.layer.borderWidth = 1;
    btn.layer.cornerRadius = 5;
    btn.layer.borderColor = bordercolor.CGColor;
    //    btn.layer.borderColor = RGBACOLOR(149, 149, 149, 1).CGColor;
    
    return btn;
}


-(UILabel*)createUIlabel:(NSString *)title andFont:(CGFloat)font andColor:(UIColor*)color {
    UILabel * label =[[UILabel alloc]init];
    label.text = title;
    label.textColor = color;
    UIFont *fnt = [UIFont fontWithName:@"HelveticaNeue" size:font];CGSize size = [label.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
    CGFloat nameH = size.height;
    CGFloat nameW = size.width;
    label.textAlignment = NSTextAlignmentCenter;
    label.frame =CGRectMake(0, 0, nameW, nameH);
    label.font = Font(font);
    return label;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
